//
//  CommunityCell.m
//  吃货·上海
//
//  Created by 濮亚军 on 15/11/24.
//  Copyright © 2015年 濮亚军. All rights reserved.
//

#import "CommunityCell.h"
#import "UIImageView+WebCache.h"
@interface CommunityCell()


@end
@implementation CommunityCell
{
    NSArray *userArray;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        //创建标题栏
        self.titleBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenHeight, 60)];
        //self.titleBgView.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:_titleBgView];
        
        //标题栏头像
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
        self.iconImageView.layer.masksToBounds = YES;
        [self.iconImageView.layer setCornerRadius:21];
        //self.iconImageView.backgroundColor = [UIColor redColor];
        self.iconImageView.image = [UIImage imageNamed:@"textIcon.jpg"];
        [self.titleBgView addSubview:_iconImageView];
        
        //标题栏用户信息
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 10, 200, 20)];
        self.nameLabel.textAlignment = NSTextAlignmentLeft;
        self.nameLabel.font = [UIFont systemFontOfSize:16];
        //self.nameLabel.text = @"随溪缘";
        [self.titleBgView addSubview:_nameLabel];
        
        self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 35, 200, 15)];
        self.timeLabel.textAlignment = NSTextAlignmentLeft;
        self.timeLabel.font = [UIFont systemFontOfSize:13];
        self.timeLabel.textColor = [UIColor grayColor];
        //self.timeLabel.text = @"1天前";
        [self.titleBgView addSubview:_timeLabel];
        
        /*
        self.focusButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.focusButton.frame = CGRectMake(KScreenWidth - 70, 10, 60, 30);
        [self.focusButton setTitle:@"+ 关注" forState:UIControlStateNormal];
        self.focusButton.titleLabel.font = [UIFont systemFontOfSize:14];
        [self.focusButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        self.focusButton.layer.masksToBounds = YES;
        [self.focusButton.layer setCornerRadius:8];
        [self.focusButton.layer setBorderWidth:0.5];
        [self.focusButton.layer setBorderColor:[UIColor blackColor].CGColor];
        [self.titleBgView addSubview:_focusButton];
        */
         
//        self.focusButton = [UIButton buttonWithType:UIButtonTypeCustom];
//        self.focusButton.frame = CGRectMake(KScreenWidth - 70, 10, 60, 30);
//        [self.focusButton setTitle:@"+ 关注" forState:UIControlStateNormal];
//        self.focusButton.titleLabel.font = [UIFont systemFontOfSize:14];
//        [self.focusButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//        self.focusButton.layer.masksToBounds = YES;
//        [self.focusButton.layer setCornerRadius:8];
//        [self.focusButton.layer setBorderWidth:0.5];
//        [self.focusButton.layer setBorderColor:[UIColor blackColor].CGColor];
//        [self.titleBgView addSubview:_focusButton];
        
        //发布图片
        self.shareImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 60, KScreenWidth, 206)];
        //self.shareImageView.image = [UIImage imageNamed:@"text.jpg"];
        self.shareImageView.userInteractionEnabled = YES;
        [self.contentView addSubview:_shareImageView];
        
        //发布内容
        self.shareInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 276, KScreenWidth - 20, 90)];
        self.shareInfoLabel.numberOfLines = 4;
        self.shareInfoLabel.textAlignment = NSTextAlignmentLeft;
        //self.shareInfoLabel.backgroundColor = [UIColor redColor];
        self.shareInfoLabel.font = [UIFont systemFontOfSize:17];
        [self.contentView addSubview:_shareInfoLabel];
        
        //评论点赞和分享朋友圈背景
        self.forumBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 376, KScreenWidth, 40)];
        //self.forumBgView.backgroundColor = [UIColor cyanColor];
        [self addSubview:_forumBgView];
        
        UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 1)];
        lineLabel.backgroundColor = [UIColor grayColor];
        [self.forumBgView addSubview:lineLabel];
        
        self.commentBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth / 3, 40)];
        [self.forumBgView addSubview:_commentBgView];
        
        CGFloat x = KScreenWidth / 9;
        CGFloat y = (40 - x / 2) / 2;
        self.commentImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x + x / 6, y, x / 2, x / 2)];
        self.commentImageView.image = [UIImage imageNamed:@"comment"];
        [self.commentBgView addSubview:_commentImageView];
        
        /*
        self.commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(x + x / 2, y, x / 2 + 10, x / 2)];
        //self.commentLabel.backgroundColor = [UIColor cyanColor];
        self.commentLabel.textAlignment = NSTextAlignmentCenter;
        self.commentLabel.text = @"111";
        self.commentLabel.font = [UIFont systemFontOfSize:11];
        [self.commentBgView addSubview:_commentLabel];
        */
//
//        self.commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(x + x / 2, y, x / 2 + 10, x / 2)];
//        //self.commentLabel.backgroundColor = [UIColor cyanColor];
//        self.commentLabel.textAlignment = NSTextAlignmentCenter;
//        self.commentLabel.text = @"111";
//        self.commentLabel.font = [UIFont systemFontOfSize:11];
//        [self.commentBgView addSubview:_commentLabel];
        
        //竖线
        UILabel *verticalLine = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth / 3, 5, 1, 30)];
        verticalLine.backgroundColor = [UIColor grayColor];
        [self.commentBgView addSubview:verticalLine];
        
        self.pointBgView = [[UIView alloc]initWithFrame:CGRectMake(KScreenWidth / 3, 0, KScreenWidth / 3, 40)];
        [self.forumBgView addSubview:_pointBgView];
        
        //竖线
        UILabel *pointVerticalLine = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth / 3, 5, 1, 30)];
        pointVerticalLine.backgroundColor = [UIColor grayColor];
        [self.pointBgView addSubview:pointVerticalLine];
        
        self.pointImageView = [[UIImageView alloc]initWithFrame:CGRectMake(x + x / 6, y, x / 2, x / 2)];
        self.pointImageView.image = [UIImage imageNamed:@"point"];
        [self.pointBgView addSubview:_pointImageView];
        /*
        self.pointLabel = [[UILabel alloc]initWithFrame:CGRectMake(x + x / 2, y, x / 2 + 10, x / 2)];
        self.pointLabel.textAlignment = NSTextAlignmentCenter;
        self.pointLabel.text = @"111";
        self.pointLabel.font = [UIFont systemFontOfSize:11];
        [self.pointBgView addSubview:_pointLabel];
        */
//        self.pointLabel = [[UILabel alloc]initWithFrame:CGRectMake(x + x / 2, y, x / 2 + 10, x / 2)];
//        self.pointLabel.textAlignment = NSTextAlignmentCenter;
//        self.pointLabel.text = @"111";
//        self.pointLabel.font = [UIFont systemFontOfSize:11];
//        [self.pointBgView addSubview:_pointLabel];
        
        //分享
        self.shareBgView = [[UIView alloc]initWithFrame:CGRectMake(2 * KScreenWidth / 3, 0, KScreenWidth, 40)];
        [self.forumBgView addSubview:_shareBgView];
        
        //竖线
        UILabel *shareVerticalLine = [[UILabel alloc]initWithFrame:CGRectMake(KScreenWidth / 3, 5, 1, 30)];
        shareVerticalLine.backgroundColor = [UIColor grayColor];
        [self.shareBgView addSubview:shareVerticalLine];
        
        self.shareToFre = [[UIImageView alloc]initWithFrame:CGRectMake(x + x / 6, y, x / 2, x / 2)];
        self.shareToFre.image = [UIImage imageNamed:@"share"];
        [self.shareBgView addSubview:_shareToFre];
        /*
        self.shareLabel = [[UILabel alloc]initWithFrame:CGRectMake(x + x / 2, y, x / 2 + 10, x / 2)];
        self.shareLabel.textAlignment = NSTextAlignmentCenter;
        self.shareLabel.text = @"分享";
        self.shareLabel.font = [UIFont systemFontOfSize:11];
        [self.shareBgView addSubview:_shareLabel];
        */
        
        //底部间隔
        self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 390, KScreenHeight, 10)];
        self.bottomView.backgroundColor = [UIColor grayColor];
        self.bottomView.alpha = 0.3;
        [self.contentView addSubview:_bottomView];
    }
    return self;
}
-(void)setUserShareModel:(UserShareModel *)userShareModel
{
    //赋值
    self.nameLabel.text = userShareModel.userName;
    
    NSDateFormatter*dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *strDate = [dateFormatter stringFromDate:userShareModel.createdAt];
    self.timeLabel.text = strDate;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:userShareModel.userIcon] placeholderImage:[UIImage imageNamed:@"textIcon.jpg"]];
    
    
    [self.shareImageView sd_setImageWithURL:[NSURL URLWithString:userShareModel.photo] placeholderImage:[UIImage imageNamed:@"text.jpg"]];
    //动态返回frame
    self.shareInfoLabel.text = userShareModel.info;
    CGRect shareInfoBounds = [userShareModel.info boundingRectWithSize:CGSizeMake(KScreenWidth - 20, 90) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName] context:nil];
    //NSLog(@"%f", shareInfoBounds.size.width);
    self.shareInfoLabel.frame = CGRectMake(10, 276, KScreenWidth - 20, shareInfoBounds.size.height);
    self.forumBgView.frame = CGRectMake(0, self.shareInfoLabel.frame.origin.y + self.shareInfoLabel.frame.size.height + 10, KScreenWidth, 40);
    self.bottomView.frame = CGRectMake(0, self.forumBgView.frame.origin.y + self.forumBgView.frame.size.height, KScreenWidth, 10);
}
//动态返回cell高度
+(CGFloat)heightForCell:(UserShareModel *)userShareModel
{
    CGRect shareInfoBounds = [userShareModel.info boundingRectWithSize:CGSizeMake(KScreenWidth - 20, 90) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:17] forKey:NSFontAttributeName] context:nil];
    return 60 + 206 + 10 + shareInfoBounds.size.height + 10 + 10 + 10 + 40;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
